//#define __DEBUG__
// by Tyrghen
#define THIS_FILE "fn_scriptedvecreactions.sqf"
#include "x_setup.sqf"

__TRACE_1("_this","_this")
if (typeName _this == typeName []) then {
	{ _x call FUNC(scriptedvecreactions);
	} foreach _this;
} else {
	if (typeName _this == typeName objNull && {!(isNull _this)}) then {
		_this addEventHandler ["HandleDamage",{
			// Only reacts when damage comes from a player, otherwise it could be a stupid AI vehicle
			if ((_this select 1) == "" && {isPlayer (_this select 3)} && {!(isNull (driver (_this select 0)))}) then {
				__TRACE_1("EH HD","_this")
				(group driver(_this select 0)) setCombatMode "RED";
				(group driver(_this select 0)) setSpeedMode "FULL";
				if ((behaviour (leader group driver(_this select 0))) in ["SAFE","AWARE"]) then { (group (_this select 0)) setBehaviour "COMBAT"; };
				(group driver(_this select 0)) reveal [(_this select 3), ((group driver(_this select 0)) knowsAbout (_this select 3)) + 0.05];
			};			
		}];
	};
}